package org.classdef.analyzer.info.accesstype;

/**
 * 
 * 类的访问类型
 *
 */
public enum ClassAccessType {
	
	ACC_PUBLIC(0x0001, "ACC_PUBLIC", "public"),
	ACC_FINAL(0x0010, "ACC_FINAL", "final"),
	ACC_SUPER(0x0020, "ACC_SUPER", "super"),
	ACC_INTERFACE(0x0200, "ACC_INTERFACE", "interface"),
	ACC_ABSTRACT(0x0400, "ACC_ABSTRACT", "abstract"),
	ACC_SYNTHETIC(0x1000, "ACC_SYNTHETIC", "synthetic"),
	ACC_ANNOTATION(0x2000, "ACC_ANNOTATION", "annotation"),
	ACC_ENUM(0x4000, "ACC_ENUM", "enum");
	
	private int type;
	private String name;
	private String shortName;
	
	private ClassAccessType(int type, String name, String shortName){
		this.type = type;
		this.name = name;
		this.shortName = shortName;
	}
	
	public int getType() {
		return type;
	}

	public String getName() {
		return name;
	}

	public String getShortName() {
		return shortName;
	}

	public static String getType(short accessFlags){
		String accessStr = null;
		
		ClassAccessType[] types = values();
		for (int i = 0; i < types.length; i++) {
			int type = types[i].getType();
			if ((accessFlags & type) == type) {
				if(accessStr == null){
					accessStr = types[i].getShortName();
				}else {
					accessStr += " " + types[i].getShortName();
				}
			}
		}
		return accessStr;
	}
}
